/*
 * 
 *
 *
 */
package com.hboxs.asl.dao.impl;

import com.hboxs.asl.dao.PlatformDao;
import com.hboxs.asl.entity.Platform;
import org.springframework.stereotype.Repository;

import javax.persistence.FlushModeType;
import javax.persistence.NoResultException;
import java.math.BigDecimal;

/**
 * Dao - 平台
 */
@Repository("platformDaoImpl")
public class PlatformDaoImpl extends BaseDaoImpl<Platform, Long> implements PlatformDao {

    @Override
    public Platform getUniqueness() {

        String jpql = "select platform from Platform platform ";
        Platform platform = null;
        try {
            platform = entityManager.createQuery(jpql, Platform.class).setFlushMode(FlushModeType.COMMIT).setMaxResults(1).getSingleResult();
        } catch (NoResultException e) {
            platform = new Platform();
            platform.setPoint(new BigDecimal(0));
            this.persist(platform);
        }
        return platform;
    }
}
